<?php

/**
 * This is the model class for table "{{hits}}".
 *
 * The followings are the available columns in table '{{hits}}':
 * @property integer $zhi_id
 * @property string $zhi_ip
 * @property string $zhi_url
 * @property integer $zm_id
 * @property integer $zp_id
 * @property integer $zhi_hits
 * @property integer $zhi_time
 * @property string $zhi_agent
 * @property integer $inputtime
 */
class Hits extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Hits the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{hits}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zhi_id, zm_id, zp_id, zhi_hits, zhi_time, inputtime, zhi_day_time', 'numerical', 'integerOnly'=>true),
			array('zhi_ip', 'length', 'max'=>50),
			array('zhi_url', 'length', 'max'=>100),
			array('zhi_agent', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zhi_id, zhi_ip, zhi_url, zm_id, zp_id, zhi_hits, zhi_time, zhi_agent, inputtime, zhi_day_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zhi_id' => 'Zhi',
			'zhi_ip' => 'Zhi Ip',
			'zhi_url' => 'Zhi Url',
			'zm_id' => 'Zm',
			'zp_id' => 'Zp',
			'zhi_hits' => 'Zhi Hits',
			'zhi_time' => 'Zhi Time',
			'zhi_day_time' => 'Zhi Day Time',
			'zhi_agent' => 'Zhi Agent',
			'inputtime' => 'Inputtime',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('zhi_id',$this->zhi_id);
		$criteria->compare('zhi_ip',$this->zhi_ip,true);
		$criteria->compare('zhi_url',$this->zhi_url,true);
		$criteria->compare('zm_id',$this->zm_id);
		$criteria->compare('zp_id',$this->zp_id);
		$criteria->compare('zhi_hits',$this->zhi_hits);
		$criteria->compare('zhi_time',$this->zhi_time);
		$criteria->compare('zhi_agent',$this->zhi_agent,true);
		$criteria->compare('inputtime',$this->inputtime);
		$criteria->compare('zhi_day_time',$this->zhi_day_time);

		$criteria->order = " inputtime DESC ";//默认为时间倒序
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}